How to “Include” in a JSON API Post in PHP?











up vote
0
down vote

favorite












I am working with the Planning Center API, it was built to conform to the JSON API 1.0 specification.



We are needing to post a persons data to Planning center. The API seems to break up a person, from their phone number and email. I am new to working with the this so I am not sure if you can post them all in the same cURL request, or if I would need 3 requests. My understanding (possibly misguided) is that I can "include" the email and phone number in the POST request.



This is what I have:



$person = '{
"data": {
"type": "Person",
"attributes": {
"first_name": "Test",
"last_name": "User"
},
"relationships": {
"primary_campus": {
"data": { "type": "PrimaryCampus", "id": "123" }
}
}
},
"include":{
"data": {
"type": "emails",
"attributes": {"address": "test@test.com"}
}
}
}';

$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://api.planningcenteronline.com/people/v2/people" );
//curl_setopt( $channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $channel, CURLOPT_USERPWD, $application_ID.":".$application_secret );
curl_setopt( $channel, CURLOPT_POST, true);
curl_setopt( $channel, CURLOPT_POSTFIELDS, $person);
curl_exec($channel);
echo $channel;


This only seems to create the persons First name and last name (and associated campus). The email is not created.



Here is the documentation for the email.
Here is the documentation for the person.



Any ideas what I am missing here?










share|improve this question






















  • it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
    – ADyson
    Nov 9 at 15:46












  • Have you tried passing the items as an array under the data element?
    – Nigel Ren
    Nov 9 at 15:46










  • I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
    – DarkSpartan47
    Nov 9 at 15:52















up vote
0
down vote

favorite












I am working with the Planning Center API, it was built to conform to the JSON API 1.0 specification.



We are needing to post a persons data to Planning center. The API seems to break up a person, from their phone number and email. I am new to working with the this so I am not sure if you can post them all in the same cURL request, or if I would need 3 requests. My understanding (possibly misguided) is that I can "include" the email and phone number in the POST request.



This is what I have:



$person = '{
"data": {
"type": "Person",
"attributes": {
"first_name": "Test",
"last_name": "User"
},
"relationships": {
"primary_campus": {
"data": { "type": "PrimaryCampus", "id": "123" }
}
}
},
"include":{
"data": {
"type": "emails",
"attributes": {"address": "test@test.com"}
}
}
}';

$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://api.planningcenteronline.com/people/v2/people" );
//curl_setopt( $channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $channel, CURLOPT_USERPWD, $application_ID.":".$application_secret );
curl_setopt( $channel, CURLOPT_POST, true);
curl_setopt( $channel, CURLOPT_POSTFIELDS, $person);
curl_exec($channel);
echo $channel;


This only seems to create the persons First name and last name (and associated campus). The email is not created.



Here is the documentation for the email.
Here is the documentation for the person.



Any ideas what I am missing here?










share|improve this question






















  • it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
    – ADyson
    Nov 9 at 15:46












  • Have you tried passing the items as an array under the data element?
    – Nigel Ren
    Nov 9 at 15:46










  • I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
    – DarkSpartan47
    Nov 9 at 15:52













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working with the Planning Center API, it was built to conform to the JSON API 1.0 specification.



We are needing to post a persons data to Planning center. The API seems to break up a person, from their phone number and email. I am new to working with the this so I am not sure if you can post them all in the same cURL request, or if I would need 3 requests. My understanding (possibly misguided) is that I can "include" the email and phone number in the POST request.



This is what I have:



$person = '{
"data": {
"type": "Person",
"attributes": {
"first_name": "Test",
"last_name": "User"
},
"relationships": {
"primary_campus": {
"data": { "type": "PrimaryCampus", "id": "123" }
}
}
},
"include":{
"data": {
"type": "emails",
"attributes": {"address": "test@test.com"}
}
}
}';

$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://api.planningcenteronline.com/people/v2/people" );
//curl_setopt( $channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $channel, CURLOPT_USERPWD, $application_ID.":".$application_secret );
curl_setopt( $channel, CURLOPT_POST, true);
curl_setopt( $channel, CURLOPT_POSTFIELDS, $person);
curl_exec($channel);
echo $channel;


This only seems to create the persons First name and last name (and associated campus). The email is not created.



Here is the documentation for the email.
Here is the documentation for the person.



Any ideas what I am missing here?










share|improve this question













I am working with the Planning Center API, it was built to conform to the JSON API 1.0 specification.



We are needing to post a persons data to Planning center. The API seems to break up a person, from their phone number and email. I am new to working with the this so I am not sure if you can post them all in the same cURL request, or if I would need 3 requests. My understanding (possibly misguided) is that I can "include" the email and phone number in the POST request.



This is what I have:



$person = '{
"data": {
"type": "Person",
"attributes": {
"first_name": "Test",
"last_name": "User"
},
"relationships": {
"primary_campus": {
"data": { "type": "PrimaryCampus", "id": "123" }
}
}
},
"include":{
"data": {
"type": "emails",
"attributes": {"address": "test@test.com"}
}
}
}';

$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://api.planningcenteronline.com/people/v2/people" );
//curl_setopt( $channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $channel, CURLOPT_USERPWD, $application_ID.":".$application_secret );
curl_setopt( $channel, CURLOPT_POST, true);
curl_setopt( $channel, CURLOPT_POSTFIELDS, $person);
curl_exec($channel);
echo $channel;


This only seems to create the persons First name and last name (and associated campus). The email is not created.



Here is the documentation for the email.
Here is the documentation for the person.



Any ideas what I am missing here?







php json-api php-curl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 15:36









DarkSpartan47

708




708












  • it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
    – ADyson
    Nov 9 at 15:46












  • Have you tried passing the items as an array under the data element?
    – Nigel Ren
    Nov 9 at 15:46










  • I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
    – DarkSpartan47
    Nov 9 at 15:52


















  • it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
    – ADyson
    Nov 9 at 15:46












  • Have you tried passing the items as an array under the data element?
    – Nigel Ren
    Nov 9 at 15:46










  • I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
    – DarkSpartan47
    Nov 9 at 15:52
















it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
– ADyson
Nov 9 at 15:46






it's not massively clear from the documentation but developer.planning.center/docs/#/introduction/json-api implies that the "include" idea is something to be used when fetching data from the API, not sending things to it. Perhaps you should ask the maintainers for clarification. Also if a person can be associated with many emails, then if the "include" thing does work for sending, then I'd guess it would expect a list (i.e. array) not just a single object. But then again that ought to result in a validation error if you supply the wrong format.
– ADyson
Nov 9 at 15:46














Have you tried passing the items as an array under the data element?
– Nigel Ren
Nov 9 at 15:46




Have you tried passing the items as an array under the data element?
– Nigel Ren
Nov 9 at 15:46












I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
– DarkSpartan47
Nov 9 at 15:52




I just tried passing the email address as an array and received an error for invalid JSON. I did also try to pass it under the data block, but also got an invalid json error. From your comments, it seems perhaps I was not far off, but the documentation is a bit to vague. I suppose I should reach out to them.
– DarkSpartan47
Nov 9 at 15:52












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










JSON API Specification v1.0 does not support bulk creation. If this specific API does not implement additional functionality that's not part of JSON API specification, you can't create a person with it's associated email in only one request.



Side note: This will likely be supported by upcoming v1.1 version trough a feature called Operations. You can find more details in this pending pull request.



So to put it short: As far as I got their specific implementation you have to create a person with first request and then create an email address associated to it with another request.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228774%2fhow-to-include-in-a-json-api-post-in-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    JSON API Specification v1.0 does not support bulk creation. If this specific API does not implement additional functionality that's not part of JSON API specification, you can't create a person with it's associated email in only one request.



    Side note: This will likely be supported by upcoming v1.1 version trough a feature called Operations. You can find more details in this pending pull request.



    So to put it short: As far as I got their specific implementation you have to create a person with first request and then create an email address associated to it with another request.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      JSON API Specification v1.0 does not support bulk creation. If this specific API does not implement additional functionality that's not part of JSON API specification, you can't create a person with it's associated email in only one request.



      Side note: This will likely be supported by upcoming v1.1 version trough a feature called Operations. You can find more details in this pending pull request.



      So to put it short: As far as I got their specific implementation you have to create a person with first request and then create an email address associated to it with another request.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        JSON API Specification v1.0 does not support bulk creation. If this specific API does not implement additional functionality that's not part of JSON API specification, you can't create a person with it's associated email in only one request.



        Side note: This will likely be supported by upcoming v1.1 version trough a feature called Operations. You can find more details in this pending pull request.



        So to put it short: As far as I got their specific implementation you have to create a person with first request and then create an email address associated to it with another request.






        share|improve this answer












        JSON API Specification v1.0 does not support bulk creation. If this specific API does not implement additional functionality that's not part of JSON API specification, you can't create a person with it's associated email in only one request.



        Side note: This will likely be supported by upcoming v1.1 version trough a feature called Operations. You can find more details in this pending pull request.



        So to put it short: As far as I got their specific implementation you have to create a person with first request and then create an email address associated to it with another request.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 17:07









        jelhan

        2,3891721




        2,3891721






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228774%2fhow-to-include-in-a-json-api-post-in-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini