33import sys
44import os
55import datetime
6-
7- # Add the parent directory to the Python path to import the SDK
8- sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
9-
6+ import postmypost_rest_sdk
107from postmypost_rest_sdk .api .publications_api import PublicationsApi
118from postmypost_rest_sdk .configuration import Configuration
129from postmypost_rest_sdk .exceptions import ApiException
1512from postmypost_rest_sdk .models .publication_detail_publication_type_enum import PublicationDetailPublicationTypeEnum
1613from postmypost_rest_sdk .models .publication_status_enum_edit import PublicationStatusEnumEdit
1714
15+ # Add the parent directory to the Python path to import the SDK
16+ sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
17+
1818# Set your API access token and project ID
19- access_token = 'YOUR_ACCESS_TOKEN '
19+ access_token = 'YOUR_API_ACCESS_TOKEN '
2020project_id = 123456
2121
2222# Configure the SDK
23- config = Configuration ()
24- config .access_token = access_token
25-
26- # Create an instance of the PublicationsApi
27- publications_api = PublicationsApi (config )
23+ configuration = Configuration (
24+ access_token = access_token
25+ )
2826
2927# Build the publication request object
3028publication_request = CreatePublicationRequest (
3129 project_id = project_id ,
3230 post_at = datetime .datetime (2025 , 6 , 30 , 12 , 0 , 0 , tzinfo = datetime .timezone .utc ), # Publication time (UTC)
3331 account_ids = [111111 , 222222 ], # Example account IDs
34- publication_status = PublicationStatusEnumEdit .NUMBER_PENDING_PUBLICATION ,
32+ publication_status = PublicationStatusEnumEdit .PENDING_PUBLICATION ,
3533 details = [
3634 PublicationDetailEditRequest (
3735 account_id = 111111 ,
38- publication_type = PublicationDetailPublicationTypeEnum .NUMBER_POST ,
36+ publication_type = PublicationDetailPublicationTypeEnum .POST ,
3937 content = "Check out our new product launch! #newproduct #launch" ,
4038 file_ids = [42516053 ],
4139 ),
4240 PublicationDetailEditRequest (
4341 account_id = 222222 ,
44- publication_type = PublicationDetailPublicationTypeEnum .NUMBER_POST ,
42+ publication_type = PublicationDetailPublicationTypeEnum .POST ,
4543 link = "https://example.com/new-product" ,
4644 ),
4745 ]
4846)
4947
50- try :
51- response = publications_api .create_publication (publication_request )
52- print ("Publication created successfully!" )
53- print (f" Publication ID: { response .id } " )
54- except ApiException as e :
55- print (f"Error while creating publication: { e } " )
48+ # Create API client context
49+ with postmypost_rest_sdk .ApiClient (configuration ) as api_client :
50+ # Create an instance of the PublicationsApi with the api_client
51+ publications_api = PublicationsApi (api_client )
52+
53+ try :
54+ response = publications_api .create_publication (publication_request )
55+ print ("Publication created successfully!" )
56+ print (f" Publication ID: { response .id } " )
57+ except ApiException as e :
58+ print (f"Error while creating publication: { e } " )
0 commit comments